package #(package);

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.demo.common.model.#(className);

/**
 * #(className) 管理	
 * 描述：
 * 
 */
public class #(className)Controller extends Controller {

	//private static final Log log = Log.getLog(#(className)Controller.class);
	
	static #(className)Service srv = #(className)Service.me;
	
	/**
	 * 列表
	 * /#(basePath)/#(classNameSmall)/list
	 */
	public void list() {
		setAttr("page", srv.paginate(getParaToInt("p", 1), 40));
		render("#(classNameSmall)List.html");
	}
	
	/**
	 * 准备添加
	 * /#(basePath)/#(classNameSmall)/add
	 */
	public void add() {
		render("#(classNameSmall)Add.html");
	}
	
	/**
	 * 保存
	 * /#(basePath)/#(classNameSmall)/save
	 */
	@Before({#(className)Validator.class})
	public void save() {
		srv.save(getModel(#(className).class));
		renderJson("isOk", true);
	}

	/**
	 * 准备更新
	 * /#(basePath)/#(classNameSmall)/edit
	 */
	public void edit() {
		#(className) #(classNameSmall) = srv.findById(getParaToInt("id"));
		setAttr("#(classNameSmall)", #(classNameSmall));
		render("#(classNameSmall)Edit.html");
	}

	/**
	 * 更新
	 * /#(basePath)/#(classNameSmall)/update
	 */
	@Before(#(className)Validator.class)
	public void update() {
		srv.update(getModel(#(className).class));
		renderJson("isOk", true);
	}

	/**
	 * 查看
	 * /#(basePath)/#(classNameSmall)/view
	 */
	public void view() {
		#(className) #(classNameSmall) = srv.findById(getParaToInt("id"));
		setAttr("#(classNameSmall)", #(classNameSmall));
		render("#(classNameSmall)View.html");
	}
	 
	/**
	 * 删除
	 * /#(basePath)/#(classNameSmall)/delete
	 */
	public void delete() {
		srv.delete(getParaToInt("id"));
		renderJson("isOk", true);
	}
	
}
